package com.ibks.iframe;

import com.ibks.iframe.log.LogManager;
import com.ibks.iframe.log.Logger;
import com.ibks.iframe.util.StringUtil;
import com.ibksystem.qm.run.internal.event.ExecutorEventObject;
import com.ibksystem.qm.run.internal.event.listener.ExecutorListener;

public class QueryExecutorListener implements ExecutorListener
{
    private Logger tlogger = LogManager.getLogger(iFrameworkInfo.DEFAULT_TRACING_LOGGER_NAME);

    private String serviceId;

    public QueryExecutorListener()
    {
        super();
    }

    public QueryExecutorListener(String serviceId)
    {
        super();
        this.serviceId = serviceId;
    }

    /* (non-Javadoc)
     * @see com.ibksystem.qm.run.internal.event.listener.ExecutorListener#executed(com.ibksystem.qm.run.internal.event.ExecutorEventObject)
     */
    public void executed(ExecutorEventObject eventObject)
    {
        StringBuffer buf = new StringBuffer();

        long executedInMillis = eventObject.getExecutedEndTime().getTimeInMillis()
                - eventObject.getExecutedStartTime().getTimeInMillis();

        buf.append(serviceId).append(iFrameworkInfo.DELIM_VERT_BAR);
        buf.append(iFrameworkInfo.PROCESS_OUT).append(iFrameworkInfo.DELIM_VERT_BAR);
        buf.append(StringUtil.padRightString(String.valueOf(executedInMillis), ' ', 5)).append(
                iFrameworkInfo.DELIM_VERT_BAR);
        buf.append(eventObject.getQueryName());

        tlogger.debug(buf.toString());
    }

}
